import { ElMessageBox } from "element-plus";

const globalFunction = {}
globalFunction.deleteConfirm = (params) => {
  // console.log(params);
  ElMessageBox.confirm(params.message || '确认删除当前数据吗？删除后无法恢复', params.value || '提示', {
    confirmButtonText: '确定',
    cancleButtonText: '取消',
    showClose: false,
    closeOnClickModal: false,
    closeOnPressEscape: false,
    beforeClose: async (action, instance, done) => {
      if (action === 'confirm') {
        const isFunc = params.thenFunc && Object.prototype.toString.call(params.thenFunc) === "[object Function]"
        instance.confirmButtonLoading = isFunc
        isFunc && params.thenFunc().then(() => {
          instance.confirmButtonLoading = false;
          done()
        }).catch(() => {
          instance.confirmButtonLoading = false;
        })
      } else {
        done()
      }
    }
  })
}
globalFunction.message = (params) => {
  console.log(params);
}

export default {
  install(app) {
    app.config.globalProperties['deleteConfirm'] = globalFunction.deleteConfirm;
    app.config.globalProperties['message'] = globalFunction.message;

  }
}